//
//  MYPhotoView.m
//  奇闻
//
//  Created by 似水灵修 on 14-11-30.
//  Copyright (c) 2014年 MingYueGuCheng. All rights reserved.
//

#import "MYPhotoView.h"
#import "UIImageView+WebCache.h"
#import "MYPhoto.h"

@interface MYPhotoView ()
@property (nonatomic, weak) UIImageView *gifV;
@end
@implementation MYPhotoView
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.userInteractionEnabled = YES;
        self.contentMode = UIViewContentModeCenter;
        self.clipsToBounds = YES;
        UIImageView *gifV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"timeline_image_gif"]];
        [self addSubview:gifV];
        self.gifV = gifV;
    }
    return self;
}
- (void)setPhoto:(MYPhoto *)photo
{
    _photo = photo;
    [self sd_setImageWithURL:photo.thumbnail_pic placeholderImage:[UIImage imageNamed:@"timeline_image_placeholder"]];
    if ([photo.thumbnail_pic.absoluteString hasSuffix:@".gif"]) {
        self.gifV.hidden = NO;
    }
    else {
        self.gifV.hidden = YES;
    }
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.gifV.x = self.width - self.gifV.width;
    self.gifV.y = self.height - self.gifV.height;
}
@end
